<?php
/**
 *
 * @authors xiadx (xiadx@zpdchina.com)
 * @date    2017-03-06 14:37:27
 * @version $Id$
 */

class ZhuyuanBlockTemplateModel extends BaseModel {

	/**
     * 返回给终端的可执行sql语句的字段名称数组
     * @var [type]
     */
    public $_field_arr = ['id','type','name','content', 'keshi', 'template_name'];

    public function ls($user_department='')
    {

        /*$block_sql = "SELECT bt.`template_type`,bt.`template_name`,bt.`suoshu_keshi`,bt.`suoshu_biaodan`,GROUP_CONCAT(bt.`template_content`separator '@') as template_content_sub,tt.`name` AS content
                      FROM zhuyuan_block_template bt
                      LEFT JOIN zhuyuan_block_template_type tt ON bt.suoshu_type_id = tt.id
                      WHERE  bt.template_type = '护理记录'
	                  AND ( bt.suoshu_keshi = '".$user_department."' OR bt.suoshu_keshi = '通用')
	                  AND (bt.suoshu_biaodan IS NOT NULL)
	                  GROUP BY bt.`template_type`,bt.`template_name`,bt.`suoshu_keshi`,bt.`suoshu_biaodan`,tt.`name`";
        $block_data = DB::query(Database::SELECT, $block_sql)->execute()->as_array();
        return $block_data;*/
    	$field_str = 'template_id as id,template_type as `type`,template_name as name,template_content as content,suoshu_keshi as keshi,suoshu_biaodan as template_name';
    	$query = DB::select($field_str)
    				->from('zhuyuan_block_template')
    				->where('yiyuan_id', '=', $this->yiyuan_id)
    				->and_where('template_type', '=', '护理记录')
    				->and_where_open()
    					->where('suoshu_keshi', '=', $user_department)
    					->or_where('suoshu_keshi', '=', '通用')
					->and_where_close()
					->and_where('suoshu_biaodan', 'is not', NULL)
                    ->execute()
                    ->as_array();
		return $query;
    }
}
